<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>cuserrnd</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="ctrlinit.html" title="ctrlinit" />
    <link rel="next" href="dam.html" title="dam" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">cuserrnd</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="ctrlinit.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="dam.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="cuserrnd"></a>
      <div class="titlepage"></div>
      <a id="IndexCuserrnd" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">cuserrnd</span>
        </h2>
        <p>cuserrnd — 
      Continuous USER-defined-distribution RaNDom generator.
          </p>
      </div>
      <div class="refsect1">
        <a id="idp97597440"></a>
        <h2>Description</h2>
        <p>
      Continuous USER-defined-distribution RaNDom generator.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp97598592"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">aout <span class="command"><strong>cuserrnd</strong></span> kmin, kmax, ktableNum</pre>
        <pre class="synopsis">iout <span class="command"><strong>cuserrnd</strong></span> imin, imax, itableNum</pre>
        <pre class="synopsis">kout <span class="command"><strong>cuserrnd</strong></span> kmin, kmax, ktableNum</pre>
      </div>
      <div class="refsect1">
        <a id="idp97603488"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>imin</em></span> -- minimum range limit
    </p>
        <p>
      <span class="emphasis"><em>imax</em></span> -- maximum range limit
    </p>
        <p>
      <span class="emphasis"><em>itableNum</em></span> -- number of table containing the random-distribution function.  Such table is generated by the user. See <a class="link" href="GEN40.html" title="GEN40">GEN40</a>, <a class="link" href="GEN41.html" title="GEN41">GEN41</a>, and <a class="link" href="GEN42.html" title="GEN42">GEN42</a>. The table length does not need to be a power of 2
    </p>
      </div>
      <div class="refsect1">
        <a id="idp97609824"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>ktableNum</em></span> -- number of table containing the random-distribution function.  Such table is generated by the user. See <a class="link" href="GEN40.html" title="GEN40">GEN40</a>, <a class="link" href="GEN41.html" title="GEN41">GEN41</a>, and <a class="link" href="GEN42.html" title="GEN42">GEN42</a>. The table length does not need to be a power of 2
    </p>
        <p>
      <span class="emphasis"><em>kmin</em></span> -- minimum range limit
    </p>
        <p>
      <span class="emphasis"><em>kmax</em></span> -- maximum range limit
    </p>
        <p>
      <span class="emphasis"><em>cuserrnd</em></span> (continuous user-defined-distribution random generator) generates random values according to a continuous random distribution created by the user. In this case the shape of the distribution histogram can be drawn or generated by any GEN routine. The table containing the shape of such histogram must then be translated to a distribution function by means of GEN40 (see <a class="link" href="GEN40.html" title="GEN40">GEN40</a> for more details). Then such function must be assigned to the XtableNum argument of cuserrnd.  The output range can then be rescaled according to the Xmin and Xmax arguments. cuserrnd linearly interpolates between table elements, so it is not recommended for discrete distributions (<a class="link" href="GEN41.html" title="GEN41">GEN41</a> and <a class="link" href="GEN42.html" title="GEN42">GEN42</a>).
    </p>
        <p>
      For a tutorial about random distribution histograms and functions see:

      </p>
        <div class="itemizedlist">
          <ul class="itemizedlist" style="list-style-type: disc; ">
            <li class="listitem">
              <p>
            D. Lorrain. "A panoply of stochastic cannons". In C. Roads, ed. 1989. Music machine. Cambridge, Massachusetts: MIT press, pp. 351 - 379.
          </p>
            </li>
          </ul>
        </div>
        <p>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp97621520"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the cuserrnd opcode. It uses the file <a class="ulink" href="examples/cuserrnd.csd" target="_top"><em class="citetitle">cuserrnd.csd</em></a>.
            </p>
        <div class="example">
          <a id="idp97623376"></a>
          <p class="title">
            <strong>Example 164. Example of the cuserrnd opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac     <span class="comment">;;;realtime audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if realtime audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o cuserrnd.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span>  <span class="op">=</span> 1

<span class="oblock">instr</span> 1	<span class="comment">; every run time same values</span>

kuser <span class="opc">cuserrnd</span> 0, 100, 1
      <span class="opc">printk</span> .2, kuser
asig  <span class="opc">poscil</span> .5, 220<span class="op">+</span>kuser, 3
      <span class="opc">outs</span> asig, asig
<span class="oblock">endin</span>

<span class="oblock">instr</span> 2	<span class="comment">; every run time different values</span>

      <span class="ohdr">seed</span> 0
kuser <span class="opc">cuserrnd</span> 0, 100, 1
      <span class="opc">printk</span> .2, kuser
asig  <span class="opc">poscil</span> .5, 220<span class="op">+</span>kuser, 3
      <span class="opc">outs</span> asig, asig
<span class="oblock">endin</span>
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">f</span> 1 0 16 -7 1 4 0 8 0 4 1	<span class="comment">;distrubution using GEN07</span>
<span class="stamnt">f</span> 2 0 16384 40 1		<span class="comment">;GEN40 is to be used with cuserrnd</span>
<span class="stamnt">f</span> 3 0 8192 10 1			<span class="comment">;sine</span>

<span class="stamnt">i</span> 1 0 2
<span class="stamnt">i</span> 2 3 2
<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />     
      Its output should include lines like these:
      </p>
        <pre class="screen">
 i   1 time     0.00067:    53.14918
 i   1 time     0.20067:     0.00000
 i   1 time     0.40067:     0.00000
 i   1 time     0.60067:    96.80406
 i   1 time     0.80067:    94.20729
 i   1 time     1.00000:     0.00000
 i   1 time     1.20067:    86.13032
 i   1 time     1.40067:    31.37096
 i   1 time     1.60067:    70.35889
 i   1 time     1.80000:     0.00000
 i   1 time     2.00000:    49.18914

WARNING: Seeding from current time 2006647442

 i   2 time     3.00067:    21.45002
 i   2 time     3.20067:    44.32333
 i   2 time     3.40067:    46.05420
 i   2 time     3.60000:     0.00000
 i   2 time     3.80067:    41.32175
 i   2 time     4.00000:     0.00000
 i   2 time     4.20000:    63.72019
 i   2 time     4.40067:     0.00000
 i   2 time     4.60067:     0.00000
 i   2 time     4.80067:     0.00000
 i   2 time     5.00000:    74.49330
      </pre>
        <p>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp97629248"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="duserrnd.html" title="duserrnd"><em class="citetitle">duserrnd</em></a>,
      <a class="link" href="urd.html" title="urd"><em class="citetitle">urd</em></a>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp97632256"></a>
        <h2>Credits</h2>
        <p>Author: Gabriel Maldonado</p>
        <p>New in Version 4.16</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="ctrlinit.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="dam.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">ctrlinit </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> dam</td>
        </tr>
      </table>
    </div>
  </body>
</html>
